Return to doc.sitecore.com

Indicating Site Section

Many sites maintain navigation state, such as highlighting a tab that represents the section into which the user has descended.  To solve this with Sitecore, when iterating over items to generate navigational components, check if the iterator is processing an Item that is in the ancestry of the primary Item the user is viewing.

1.  XSL Rendering Code

<xsl:for-each select="$home/item[@template='section']">
  
<xsl:sort select="@sortorder" data-type="number" />
  
<xsl:variable name="navclass">
  
<xsl:choose>
    
<xsl:when test="count( $sc_currentitem/ancestor-or-self::item[@id = current()/@id] )
      &gt; 0"
>nav_highlighted</xsl:when>
    
<xsl:otherwise>nav_normal</xsl:otherwise>
  
</xsl:choose>
  
</xsl:variable>
  
<sc:link class="{$navclass}"><xsl:call-template name="GetNavTitle"></sc:link>
  
<xsl:if test="position() != last()"><br /></xsl:if>
</xsl:for-each>